#!/bin/bash

version=$(cat python-daemonize.spec |grep "^Version"|awk '{print $2}')
srcfile="daemonize-${version}.tar.gz"
specfile="python-daemonize.spec"

if [ $# -eq 0 ];then
  echo "Usage: $0 -ba|-bp"
  exit
fi
HOME=/tmp/`whoami`
builddir=${HOME}/rpmbuild
mkdir -p  $builddir/SOURCES $builddir/SPECS

if [ ! -f $srcfile ]; then
 wget https://pypi.python.org/packages/84/15/923e3fe48239adf5d697c29e04a3f868d3e4ce8539aab29d6abe784db5be/$srcfile
fi

cp $srcfile  ${builddir}/SOURCES/

cp *.patch ${builddir}/SOURCES/

cp ${specfile} ${builddir}/SPECS/
cd ${builddir}/SPECS && rpmbuild ${1} ${specfile}
